<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
<!--    <meta http-equiv="refresh" content="5">-->
    <title>fwh-留言板功能demo</title>
</head>
<script src="../vue.js"></script>
<script src="../lib/jquery-1.7.2.js"></script>
<script src="../lib/bootstrap.js"></script>
<link rel="stylesheet" href="../lib/bootstrap.min.css">
<!--<script src="../lib/bootstrap.min.css"></script>-->

<script>
    window.onload = function () {
        new Vue({
            el: '#box',
            data: {
                myData:[],
                username: '',
                age: '',
                nowIndex:-100
            },
            methods:{
                add(){
                    this.myData.push({
                        name:this.username,
                        age: this.age
                    });
                    this.username='';
                    this.age='';
                },
                deleteMsg(n){
                    if (n == -2) {
                        this.myData=[];
                    }else {
                        this.myData.splice(n,1);
                    }
                }
            }
        })
    }
</script>
<body>
<div id="box" class="container">
    <form role="form">
        <div class="form-group">
            <label for="username">用户名:</label>
            <input type="text" id="username" v-model="username" class="form-control" placeholder="请输入用户名">
        </div>
        <div class="form-group">
            <label for="age">年 龄:</label>
            <input type="text" id="age" v-model="age" class="form-control" placeholder="请输入年龄">
        </div>
        <div class="form-group">
            <input type="button" value="添加" class="btn btn-primary" @click="add()">
            <input type="reset" value="重置" class="btn btn-danger">
        </div>
    </form>

    <hr/>

    <table class="table table-bordered table-hover">
        <caption class="h3 text-info">用户信息表</caption>
        <tr class="text-danger">
            <th class="text-center">序号</th>
            <th class="text-center">名字</th>
            <th class="text-center">年龄</th>
            <th class="text-center">操作</th>
        </tr>
        <tr class="text-center" v-for="item in myData">
            <td>{{$index+1}}</td>
            <td>{{item.name}}</td>
            <td>{{item.age}}</td>
            <td>
                <button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#layer" @click="nowIndex=$index">删除</button>
            </td>
        </tr>
        <tr v-show="myData.length!=0">
            <td colspan="4" class="text-right">
                <button class="btn btn-danger btn-sm" @click="nowIndex=-2" data-toggle="modal" data-target="#layer">删除全部</button>
            </td>
        </tr>
        <tr v-show="myData.length==0">
            <td colspan="4" class="text-center text-muted">
                <p>暂无数据...</p>
            </td>
        </tr>
    </table>
    <!--动态弹出框-->
    <div id="layer" role="dialog" class="modal fade bs-example-modal-sm">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span>*</span>
                    </button>
                    <h4 class="modal-title">确认删除么</h4>
                </div>
                <div class="modal-body text-right">
                    <button data-dismiss="modal" class="btn btn-primary btn-sm">取消</button>
                    <button data-dismiss="modal" class="btn btn-danger btn-sm" @click="deleteMsg(nowIndex)">确认</button>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>